<!-- 手机端导航 -->
<template>
<section class="mainNavWap" v-show="showNavs" @click="hideNavs">
    <div class="wCen">
        <input v-model="haNum" type="hidden" />
        <ul class="mainNavWap__nav">
            <!--导航类型 （1：外链，2：内部路由，3：在线编辑）-->
            <li v-for="(item,i) in navs" :key="i">
                <span>
                    <span @click.stop="openPage(item)">{{item.title}}</span>
                    <img src="@/assets/img/icon_down.svg" @click.stop="showChild(item)" class="iconDown" v-if="item.children&&item.children.length>0" :class="{collapse:item.isCollapse}" />
                </span>
                <div v-if="item.children&&item.children.length>0&&item.isCollapse">
                    <ol class="secondMenu">
                        <li v-for="(child,j) in item.children" :key="j" class="second">
                            <a @click.stop="openPage(child)">{{child.title}}</a>
                        </li>
                    </ol>
                </div>
            </li>
        </ul>
    </div>
</section>
</template>

<script>
import {
    getChannelList,
} from "@/api/common";
import util from "@/libs/util.js";
export default {
    data() {
        return {
            isCollapse: false,
            haNum: 0,
            navs: [],
        };
    },
    computed: {
        // 点击遮罩层隐藏菜单
        showNavs() {
            return this.$store.state.data.showNavs
        },
    },
    mounted() {
        this.getChannelListFun()
    },
    methods: {
        hideNavs() {
            this.$store.commit('submitShowNavs', false)
        },
        showChild(v) {
            if (v.children && v.children.length) {
                this.$set(v, 'isCollapse', !v.isCollapse)
                this.haNum++;
                return
            }
        },
        getChannelListFun() {
            // 加载导航
            this.invoke(getChannelList).then(res => {
                if(res&&res.code==200){
                    this.navs = res.data
                }
            });
        }
    },
};
</script>
<style lang="scss" scoped>
@media (min-width:768px) and (max-width:999px) {
   .mainNavWap {
    .wCen{
        width:100%;
        padding:0 15px;
    }
   }
}
</style>

<style lang="scss" scoped>
.mainNavWap {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 999999;
    background-color: #00000066;
    width: 100%;

    .wCen {
        background-color: #fff;
        box-sizing: border-box;
    }

    /* 页面导航 s*/
    &__nav {
        padding: 20px 0;

        li {
            min-height: 40px;

            >a,
            >span {
                display: inline-block;
                font-weight: bold;
                font-size: 14px;
                text-align: center;
                color: #191E33;
                position: relative;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                word-break: keep-all;
                display: flex;
                justify-content: space-between;
                align-items: center;

                &:hover,
                &.active {
                    opacity: 0.8
                }
            }

            &.active {
                a {
                    opacity: 0.8
                }
            }

            .iconDown {
                transition: all 0.2s linear;
                width: 16px;

                &.collapse {
                    transform: rotate(180deg);
                }
            }
        }
        // 二级菜单
        .secondMenu {
            padding-left: 20px;
            position: relative;
            top: 10px;
            padding-bottom: 30px;
            li {
                height: 40px;
                line-height: 40px;
                a {
                    font-weight: normal;
                    font-size: 14px;
                }
            }
        }

        >li.second {
            position: relative;

            >a:after {
                content: "";
                display: inline-block;
                width: 100%;
                height: 4px;
                background-color: transparent;
                position: absolute;
                bottom: -20px;
                left: 0;
            }

            &:hover {
                ol {
                    display: block;
                }
            }

            >a:hover:after,
            >a.active:after {
                background-color: #e50113;
            }
        }
    }
}
</style>
